﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
using Utility;
namespace Service
{
    /// <summary>
    /// 功能：HW_Standard类数据访问
    /// 创建人：Wilson
    /// 创建时间：2013-1-30   
    /// </summary>
    public class HW_StandardService : IDisposable
    {
        #region 公共
        private System.ComponentModel.Component component = new System.ComponentModel.Component();

        private bool disposed = false;

        ~HW_StandardService()
        {
            Dispose(false);
        }

        #endregion

        #region IDisposable 成员

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {

                if (disposing)
                {

                    component.Dispose();
                }

                disposed = true;

            }
        }
        #endregion
		#region##MapperHW_Standard
        public IList<HW_Standard> MapperList(SqlDataReader reader)
         {
            IList<HW_Standard> list = new List<HW_Standard>();
            HW_Standard obj=null;
            while (reader.Read())
            {
                obj = new HW_Standard();
                obj.StandardCode = (int)reader["StandardCode"];
                obj.ItemId = reader["ItemId"] as int?;
                obj.BanBen = reader["BanBen"] as int?;
                obj.Sex = reader["Sex"] as string;
                obj.Age = reader["Age"] as int?;
                obj.Min = reader["Min"] as decimal?;
                obj.Max = reader["Max"] as decimal?;
                list.Add(obj);
            }
            return list;
         }
        public HW_Standard Mapper(SqlDataReader reader)
         {
            HW_Standard obj=null;
            if (reader.Read())
            {
                obj = new HW_Standard();
                obj.StandardCode = (int)reader["StandardCode"];
                    obj.ItemId = reader["ItemId"] as int?;
                    obj.BanBen = reader["BanBen"] as int?;
                obj.Sex = reader["Sex"] as string;
                    obj.Age = reader["Age"] as int?;
                    obj.Min = reader["Min"] as decimal?;
                    obj.Max = reader["Max"] as decimal?;
            }
            return obj;
         }
        #endregion
        #region##通过主键ID得到HW_Standard
        /// <summary>
        /// 功能：通过ID得到HW_Standard
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
        public HW_Standard GetById(int standardcode)
        {            
            string sql = "select * from HW_Standard where StandardCode = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",4)
            };
            
            SqlDataReader reader=SqlHelper.ExecuteReader(WebConn.connString,CommandType.Text,sql,sp);
            return Mapper(reader);
        }
        #endregion
		
		#region##通过主键ID删除HW_Standard
        /// <summary>
        /// 功能：通过主键ID删除HW_Standard
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
		public int DeleteById(int standardcode)
		{
			int i = 0;
			string sql = "delete from HW_Standard where StandardCode = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",4)
            };
            i= SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
			return i;
		}
        /// <summary>
        /// 功能：通过主键ID删除HW_Standard
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
		public int DeleteById(SqlTransaction transaction,int standardcode)
		{
			int i = 0;
			string sql = "delete from HW_Standard where StandardCode = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",4)
            };
            i= SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
			return i;
		}
		#endregion			
		
        #region##添加HW_Standard
        /// <summary>
        /// 功能：添加HW_Standard
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int Add(HW_Standard hw_standard)
        {
            int result = 0;
            string sql = "insert into HW_Standard(StandardCode,ItemId,BanBen,Sex,Age,Min,Max) values(@StandardCode,@ItemId,@BanBen,@Sex,@Age,@Min,@Max)";			
            SqlParameter[] sp = new SqlParameter[]
            {
				new SqlParameter("@StandardCode",hw_standard.StandardCode),
				new SqlParameter("@ItemId",hw_standard.ItemId),
				new SqlParameter("@BanBen",hw_standard.BanBen),
				new SqlParameter("@Sex",hw_standard.Sex),
				new SqlParameter("@Age",hw_standard.Age),
				new SqlParameter("@Min",hw_standard.Min),
				new SqlParameter("@Max",hw_standard.Max)
            };
            result = SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
            return result;
        }
         /// <summary>
        /// 功能：添加HW_Standard
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int Add(SqlTransaction transaction,HW_Standard hw_standard)
        {
            int result = 0;
            string sql = "insert into HW_Standard(StandardCode,ItemId,BanBen,Sex,Age,Min,Max) values(@StandardCode,@ItemId,@BanBen,@Sex,@Age,@Min,@Max)";			
            SqlParameter[] sp = new SqlParameter[]
            {
				new SqlParameter("@StandardCode",hw_standard.StandardCode),
				new SqlParameter("@ItemId",hw_standard.ItemId),
				new SqlParameter("@BanBen",hw_standard.BanBen),
				new SqlParameter("@Sex",hw_standard.Sex),
				new SqlParameter("@Age",hw_standard.Age),
				new SqlParameter("@Min",hw_standard.Min),
				new SqlParameter("@Max",hw_standard.Max)
            };
            result = SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
            return result;
        }
        #endregion
		
		#region##得到HW_Standard集合
		/// <summary>
        /// 功能：得到HW_Standard集合
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>       
        /// <returns></returns>
		public IList<HW_Standard> GetList()
		{
			string sql = "select * from HW_Standard";			
			SqlDataReader reader = SqlHelper.ExecuteReader(WebConn.connString,CommandType.Text,sql);
            return MapperList(reader);
		}
		#endregion
		
		#region##修改HW_Standard
        /// <summary>
        /// 功能：修改HW_Standard
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int ModHW_Standard(HW_Standard hw_standard)
        {
            int result = 0;
            string sql = "update HW_Standard set StandardCode = @StandardCode,ItemId = @ItemId,BanBen = @BanBen,Sex = @Sex,Age = @Age,Min = @Min,Max = @Max where StandardCode = @StandardCode";
            SqlParameter[] sp = new SqlParameter[]
            {       
				new SqlParameter("@StandardCode",hw_standard.StandardCode),
				new SqlParameter("@ItemId",hw_standard.ItemId),
				new SqlParameter("@BanBen",hw_standard.BanBen),
				new SqlParameter("@Sex",hw_standard.Sex),
				new SqlParameter("@Age",hw_standard.Age),
				new SqlParameter("@Min",hw_standard.Min),
				new SqlParameter("@Max",hw_standard.Max)
            };
            result = SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
            return result;
        }
         /// <summary>
        /// 功能：修改HW_Standard
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int ModHW_Standard(SqlTransaction transaction,HW_Standard hw_standard)
        {
            int result = 0;
            string sql = "update HW_Standard set StandardCode = @StandardCode,ItemId = @ItemId,BanBen = @BanBen,Sex = @Sex,Age = @Age,Min = @Min,Max = @Max where StandardCode = @StandardCode";
            SqlParameter[] sp = new SqlParameter[]
            {       
				new SqlParameter("@StandardCode",hw_standard.StandardCode),
				new SqlParameter("@ItemId",hw_standard.ItemId),
				new SqlParameter("@BanBen",hw_standard.BanBen),
				new SqlParameter("@Sex",hw_standard.Sex),
				new SqlParameter("@Age",hw_standard.Age),
				new SqlParameter("@Min",hw_standard.Min),
				new SqlParameter("@Max",hw_standard.Max)
            };
            result = SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
            return result;
        }
        #endregion
		
		#region##统计HW_Standard
		/// <summary>
        /// 修改HW_Standard
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
		public int SelectCount()
		{
			int i = 0;
            string sql = "select count(*) from HW_Standard";
            i = (int)SqlHelper.ExecuteScalar(WebConn.connString,CommandType.Text,sql);
            return i;
		}
		/// <summary>
        /// 修改HW_Standard
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int SelectCountById()
        {
            int i=0;
            string sql="select count(StandardCode) from HW_Standard";
            i = (int)SqlHelper.ExecuteScalar(WebConn.connString,CommandType.Text,sql);
            return i;
        }
		#endregion
        #region##自定义HW_Standard
        #endregion
                
    }
}
